package cn.jly.spring.annotation.ioc.config.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author lanyangji
 * @description 判断是否是windows系统
 * @date 2020/11/12 上午 9:50
 */
public class WindowsCondition implements Condition {
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 获取ioc使用的beanFactory
        final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        // 获取类加载器
        final ClassLoader classLoader = context.getClassLoader();
        // 获取bean定义的注册类
        final BeanDefinitionRegistry registry = context.getRegistry();
        // 获取环境信息
        final Environment environment = context.getEnvironment();
        final String osName = environment.getProperty("os.name");
        if (osName == null) {
            return false;
        }

        return osName.toUpperCase().contains("WINDOWS");
    }
}
